var util = require('../../utils/util.js');
var WXBizDataCrypt = require('../../crypto/WXBizDataCrypt.js');
let app = getApp();
let url = app.url;
let gobalData = app.gobalData;
Page({

	/**
	 * 页面的初始数据
	 */
	data: {
		mobile: null,
		iptFlag: true,
    supervisionid: null,
		leaderId: null,
		name: '',
		address: ''
	},
	nameChange(val){
		this.setData({
			name: val.detail.value
		})
	},
	addressChange(val){
		this.setData({
			address: val.detail.value
		})
	},
	// 提交用户报名的信息
	formSubmit: function(e) {
		let cid = wx.getStorageSync("userInfo").userInfo.id;
		let mobile = this.data.mobile;
		let name = this.data.name;
		let address = this.data.address;
		let reg = /^[\u4E00-\u9FA5\uf900-\ufa2d·s]{2,20}$/;//验证姓名
		// console.log(name,address);
		let obj = {
			cid,
			mobile,
			name,
			address,
      supervisionId: this.data.supervisionid
		};
		if (name.length < 1 || address.length <= 1) {
			wx.showToast({
				title: "你还没有输入姓名或地址",
				icon: "none"
			})
			return;
		} else if (!reg.test(name)) {
			wx.showToast({
				title: "姓名输入有误，请重新输入！",
				icon: "none"
			})
		} else {
			util(`${url}SupervisionApply/addSupervisionApply`, obj).then(res => {
//         console.log('传递的数据：',obj);
//         console.log('接收的数据：',res);
				if (res.status == 1) {
					wx.showToast({
						title: "报名成功"
					})
					wx.navigateTo({
						url: "/pages/supervisorEnrollShare/index"
					})
				} else {
					wx.showToast({
						title: res.msg,
						icon: "none"
					})
				}
			})
		}
	},
	userData(e){
		this.setData({
			mobile: e.detail.content.userInfo.mobile
		})
	},
	iptFlag(e){
		this.setData({
			iptFlag: e.detail
		})
	},
	/**
	 * 生命周期函数--监听页面加载
	 */
	onLoad: function(options) {
    this.setData({
      supervisionid: options.supervisionid,
			leaderId: options.leaderId
    })
		try{
			this.setData({
				mobile: wx.getStorageSync("userInfo").userInfo.mobile
			})
		}catch(e){
		}
	},

	/**
	 * 生命周期函数--监听页面初次渲染完成
	 */
	onReady: function() {

	},

	/**
	 * 生命周期函数--监听页面显示
	 */
	onShow: function() {

	},

	/**
	 * 生命周期函数--监听页面隐藏
	 */
	onHide: function() {

	},

	/**
	 * 生命周期函数--监听页面卸载
	 */
	onUnload: function() {

	},

	/**
	 * 页面相关事件处理函数--监听用户下拉动作
	 */
	onPullDownRefresh: function() {

	},

	/**
	 * 页面上拉触底事件的处理函数
	 */
	onReachBottom: function() {

	},

	/**
	 * 用户点击右上角分享
	 */
	onShareAppMessage: function() {

	}
})
